package com.bitinstitute.parkapp.animals.types;

import java.util.ArrayList;
import java.util.HashMap;

import com.bitinstitute.parkapp.R;
import com.bitinstitute.parkapp.helper.ImageLoader;



import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class TypesAdapter extends BaseAdapter {
    
    private Activity activity;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater = null;
    public ImageLoader imageLoader; 
    
    public TypesAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
        activity = a;
        data = d;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        imageLoader = new ImageLoader(activity.getApplicationContext());
    }

    public int getCount() {
        return data.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(convertView==null)
            vi = inflater.inflate(R.layout.types_list_row, null);

        TextView name = (TextView)vi.findViewById(R.id.name); 
        TextView sci_name = (TextView)vi.findViewById(R.id.sci_name);       
        TextView origin = (TextView)vi.findViewById(R.id.origin);
        TextView food = (TextView)vi.findViewById(R.id.food);
        TextView size = (TextView)vi.findViewById(R.id.size);
        TextView weight = (TextView)vi.findViewById(R.id.weight);
        TextView incubation = (TextView)vi.findViewById(R.id.incubation);
        TextView eggs = (TextView)vi.findViewById(R.id.eggs);
        TextView age = (TextView)vi.findViewById(R.id.age);
        TextView place = (TextView)vi.findViewById(R.id.place);
        TextView desc1 = (TextView)vi.findViewById(R.id.desc1);
        TextView heading1 = (TextView)vi.findViewById(R.id.heading1);
        TextView desc2 = (TextView)vi.findViewById(R.id.desc2);
        TextView heading2 = (TextView)vi.findViewById(R.id.heading2);
        TextView desc3 = (TextView)vi.findViewById(R.id.desc3);
        TextView heading3 = (TextView)vi.findViewById(R.id.heading3);
        TextView thumb_url = (TextView)vi.findViewById(R.id.thumb_url);  
        ImageView thumb_image = (ImageView)vi.findViewById(R.id.list_image); // thumb image
        TextView sound = (TextView)vi.findViewById(R.id.sound);
        TextView video = (TextView)vi.findViewById(R.id.video);
        
        HashMap<String, String> animal = new HashMap<String, String>();
        animal = data.get(position);
        
        // Setting all values in listview
        name.setText(animal.get(TypesMenuActivity.KEY_NAME));
        sci_name.setText(animal.get(TypesMenuActivity.KEY_SCI)); 
        origin.setText(animal.get(TypesMenuActivity.KEY_ORIGIN));
        food.setText(animal.get(TypesMenuActivity.KEY_FOOD));
        size.setText(animal.get(TypesMenuActivity.KEY_SIZE));
        weight.setText(animal.get(TypesMenuActivity.KEY_WEIGHT));
        incubation.setText(animal.get(TypesMenuActivity.KEY_INCUBATION));
        eggs.setText(animal.get(TypesMenuActivity.KEY_EGGS));
        age.setText(animal.get(TypesMenuActivity.KEY_AGE));
        place.setText(animal.get(TypesMenuActivity.KEY_PLACE));
        heading1.setText(animal.get(TypesMenuActivity.KEY_HEADING1));
        desc1.setText(animal.get(TypesMenuActivity.KEY_DESC1));
        heading2.setText(animal.get(TypesMenuActivity.KEY_HEADING2));
        desc2.setText(animal.get(TypesMenuActivity.KEY_DESC2));
        heading3.setText(animal.get(TypesMenuActivity.KEY_HEADING3));
        desc3.setText(animal.get(TypesMenuActivity.KEY_DESC3));
        thumb_url.setText(animal.get(TypesMenuActivity.KEY_THUMB_URL));
        imageLoader.DisplayImage(animal.get(TypesMenuActivity.KEY_THUMB_URL), thumb_image);
        sound.setText(animal.get(TypesMenuActivity.KEY_SOUND));
        video.setText(animal.get(TypesMenuActivity.KEY_VIDEO));
        return vi;
    }
}